package www.wen.com.common.lib.helper.loading

import android.view.LayoutInflater
import android.view.ViewGroup
import com.dylanc.loadingstateview.LoadingStateView
import com.dylanc.loadingstateview.LoadingStateView.ViewHolder
import www.wen.com.common.R
import www.wen.com.common.lib.extension.getColorAgency


/**
 * @author WEN
 * @Description:
 * @date 2020/12/8 14:52
 */
class LoadingAdapter(
        private val colorRes: Int = R.color.colorFFFFFF,
        private val layoutRes: Int = R.layout.layout_loading,
): LoadingStateView.ViewDelegate<ViewHolder>() {

    private var height = ViewGroup.LayoutParams.MATCH_PARENT

    override fun onCreateViewHolder(inflater: LayoutInflater, parent: ViewGroup): ViewHolder {
        return ViewHolder(inflater.inflate(layoutRes, parent, false))
    }

    override fun onBindViewHolder(holder: ViewHolder) {
        val layoutParams: ViewGroup.LayoutParams = holder.rootView.layoutParams
        holder.rootView.setBackgroundColor(getColorAgency(colorRes))
        layoutParams.height = height
        holder.rootView.layoutParams = layoutParams
    }
}